import { Loading } from 'element-ui';
export default {
    methods: {
        /**
         *  通用api请求方法
         *  @param { Function } reqeustFn api请求方法
         *  @param { Function } callBack 回调函数
         *  @param { Object } resPar 请求参数
         *  @param { Function } eroBack 请求出错回调函数
         */
        comResquest(reqeustFn,callBack,resPar={},eroBack) {
            console.log(reqeustFn)
            console.log('comApi');
            let _self = this;
            let load = resPar.load;
            if (load) {
                if (typeof load === "boolean") {
                    this.loading = true;
                }else{
                    this[load] = true;
                }
            }
            delete resPar.load;
            reqeustFn(resPar).then((res)=>{
                if (load) {
                    if (typeof load === "boolean") {
                        _self.loading = false;
                    }else{
                        _self[load] = false;
                    }
                }
                let { code,data,message } = res.data;
                let compatibilityHint = data &&  ',' + data.info  || '';
                compatibilityHint =  message + compatibilityHint;
                if (Number(code) === 0) {
                    if (callBack) {
                        callBack(data,compatibilityHint);
                    }else{
                        _self.$notify.error({title: '错误',message: compatibilityHint});
                    }
                }else{
                    eroBack && eroBack();
                    _self.$notify.error({title: '错误',message: compatibilityHint});
                }
            });
        },
    },
}
